package com.jackeysun.app_common

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.widget.ViewPager2
import com.jackeysun.app_common.databinding.ActivityMain6Binding
import com.jackeysun.common.ImageClickHandler
import com.jackeysun.common.binding
import com.jackeysun.common.showRich
import kotlinx.coroutines.launch

class MainActivity6 : AppCompatActivity() {

    private val mBinding: ActivityMain6Binding by binding(ActivityMain6Binding::inflate)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        mBinding = ActivityMain6Binding.inflate(layoutInflater)
//        setContentView(mBinding.root)


        lifecycleScope.launch {
//            val doc = Jsoup.connect(DataSource.url).timeout(10000).get()
//            val html = DataSource.url.connect()
//            val html = "https://gitee.com/jackeysun/common-kit".connect()
            mBinding.tv.showRich(DataSource.img3, "img", ImageClickHandler(this@MainActivity6))
        }
    }
}

//webclient = new WebClient(BrowserVersion.FIREFOX_17);
//webclient.getOptions().setJavaScriptEnabled(true);
//webclient.getOptions().setThrowExceptionOnScriptError(false);
//webclient.getOptions().setCssEnabled(false);
//webclient.getCookieManager().clearCookies();
//webclient.getCache().clear();
//webclient.setRefreshHandler(new ImmediateRefreshHandler());
//webclient.getOptions().setTimeout(600*1000);
//webclient.setJavaScriptTimeout(600*1000);
//webclient.setAjaxController(new NicelyResynchronizingAjaxController());
//webclient.getOptions().setJavaScriptEnabled(true);
//webclient.setJavaScriptTimeout(600*1000);
//webclient.getOptions().setRedirectEnabled(true);
//webclient.waitForBackgroundJavaScript(60*1000);
//webclient.getOptions().setThrowExceptionOnScriptError(false);
//webclient.getOptions().setThrowExceptionOnFailingStatusCode(false);
//webclient.getOptions().setUseInsecureSSL(true);

//val TIME_OUT :Long =  600*1000
//suspend fun String.connect(): String {
//    return withContext(Dispatchers.IO) {
//        val webClient = WebClient(BrowserVersion.CHROME)
//        webClient.cookieManager.clearCookies()
//        webClient.cache.clear()
//        webClient.refreshHandler = ImmediateRefreshHandler()
//        webClient.ajaxController = NicelyResynchronizingAjaxController()
//        webClient.waitForBackgroundJavaScript(TIME_OUT) // 等待js后台执行30秒
//        webClient.javaScriptTimeout = TIME_OUT
//
//        val option = webClient.options
//        option.isJavaScriptEnabled = true
//        option.isUseInsecureSSL = true
//        option.isCssEnabled = false
//        option.isThrowExceptionOnScriptError = false
//        option.isThrowExceptionOnFailingStatusCode = false
//        option.timeout = TIME_OUT.toInt()
//        option.isRedirectEnabled = true
//        val page: HtmlPage = webClient.getPage(this@connect)
//        val pageAsXml = page.asXml()
//        val doc = Jsoup.parse(pageAsXml, this@connect)
////        val doc = Jsoup.connect(this@connect).timeout(10000).get()
//
//        doc.html()
//    }
//}